package model;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

public class RequestModel extends ListDataModel<Request> implements SelectableDataModel<Request>{

	public RequestModel (List<Request> data) {
        super(data);
    }
    
    @Override
    public Request getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data
        
        List<Request> requests = (List<Request>) getWrappedData();
        
        for(Request request : requests) {
            int r = request.getId();
               	if(Integer.toString(request.getId()).equals(rowKey))
                return request;
        }
        
        return null;
    }

    @Override
    public Object getRowKey(Request request) {
        return request.getId();
    }
}
